package com.xpec.canaan.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;

public class LoadMD5Recorder {
	
	public LoadMD5Recorder(String filepath)
	{
		m_filePath = filepath;
	}
	
	public Hashtable<String, String> parserFileMD5() throws FileNotFoundException , IOException
	{
		File file = new File(m_filePath);
		if( !file.exists() )
		{
			throw new IOException(m_filePath + " could not found");
		}
		
		Hashtable<String, String> fileMap = new Hashtable<String, String>();
		
		
		BufferedReader fin = new BufferedReader(new FileReader(file));
		String str;
		while((str = fin.readLine()) != null)
		{
			parserSingleLine(str,fileMap);
		}
		fin.close();
		
		return fileMap;
	}
	
	private void parserSingleLine(String line, Hashtable<String, String> table)
	{
		if( null != line && "" != line )
		{
			int cutAt = line.indexOf(":");
			if( -1 != cutAt )
			{
				String key = line.substring(0, cutAt);
				String value = line.substring(cutAt+1, line.length());
				
				table.put(key, value);
			}
		}
	}
	
	private String m_filePath;
}
